/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject.Engine
{
	public sealed class DynamicBuildStep : BuildStep<IBuildEngine>
	{
		#region Public Properties
		public override string Name
		{
			get
			{
				return name;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string name;
		private readonly BuildStepExecuteCallback executeCallback;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="DynamicBuildStep" /> class.
		/// </summary>
		public DynamicBuildStep(IBuildEngine engine, BuildStepExecuteCallback executeCallback, 
			string name, bool runInBackground, bool continueOnError, bool includeInPartialBuild)
			: base(engine)
		{
			if (executeCallback == null)
				throw new ArgumentNullException("executeCallback");

			if (string.IsNullOrEmpty(name))
				throw new ArgumentException(Resources.Errors.NullOrEmpty, "name");

			this.executeCallback = executeCallback;
			this.name = name;
			this.RunInBackground = runInBackground;
			this.ContinueOnError = continueOnError;
			this.IncludeInPartialBuild = includeInPartialBuild;
		}
		#endregion

		#region Methods
		protected override void ExecuteInternal(BuildContext context)
		{
			executeCallback(context);
		}

		protected override void CancelInternal(BuildContext context)
		{
			// Do nothing.  It's up to the callback delegate to check context.Canceled itself.
		}
		#endregion
	}
}
